package com.xiangmu.controler;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xiangmu.mappers.DongwuMapper;
import com.xiangmu.mappers.LingyangMapper;
import com.xiangmu.pojo.Dongwu;
import com.xiangmu.pojo.Lingyang;
import com.xiangmu.util.JsonResult;

@RestController
public class LingyangControler extends BaseController
{

	@Autowired
	private LingyangMapper lingyangMapper;
	
	@Autowired
	private DongwuMapper dongwuMapper;
	
	@RequestMapping("/lingyangAdd")
	public JsonResult<Void> lingyangAdd(@RequestBody Lingyang lingyang) 
	{
		lingyangMapper.insert(lingyang);
		
		dongwuMapper.updateZt(lingyang.getDongwu_id(), "已领养");
        return new JsonResult<>(66);
		
    }
	
	
	@RequestMapping("/lingyangMana")
	public JsonResult<List> lingyangMana() 
	{
		List<Lingyang> lingyangList=lingyangMapper.select("","");
		for(Lingyang lingyang : lingyangList)
		{
			lingyang.setDongwu(dongwuMapper.findByid(lingyang.getDongwu_id()));
		}
		return new JsonResult<>(66,lingyangList);
		
    }
	
	@RequestMapping("/lingyangDel")
	public JsonResult<Void> lingyangDel(int id) 
	{
		lingyangMapper.delete(id);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/lingyangUpdate")
	public JsonResult<Void> update(@RequestBody Lingyang lingyang) 
	{
		lingyangMapper.update(lingyang);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/lingyangRes")
	public JsonResult<List> lingyangRes(String xingming) 
	{
		
		List<Lingyang> lingyangList=lingyangMapper.select(xingming.trim(),"");
		for(Lingyang lingyang : lingyangList)
		{
			lingyang.setDongwu(dongwuMapper.findByid(lingyang.getDongwu_id()));
		}
		return new JsonResult<>(66,lingyangList);
		
    }
	
	
}
